home *** CD-ROM | disk | FTP | other *** search
/ Planet Source Code Jumbo …e CD Visual Basic 1 to 7 / 5_2007-2008.ISO / data / Zips / ucClock_-_2055933242007.psc / Clock Usercontrol / c32bppDIB.cls
Text File  |  2007-03-20  |  48KB  |  781 lines

  1. VERSION 1.0 CLASS
  2. BEGIN
  3.   MultiUse = -1  'True
  4.   Persistable = 0  'NotPersistable
  5.   DataBindingBehavior = 0  'vbNone
  6.   DataSourceBehavior  = 0  'vbNone
  7.   MTSTransactionMode  = 0  'NotAnMTSObject
  8. END
  9. Attribute VB_Name = "c32bppDIB"
  10. Attribute VB_GlobalNameSpace = False
  11. Attribute VB_Creatable = True
  12. Attribute VB_PredeclaredId = False
  13. Attribute VB_Exposed = False
  14. Option Explicit
  15.  
  16. ' Credits/Acknowledgements - Thanx goes to:
  17. '   Paul Caton for his class on calling non VB-Friendly DLLs that use _cdecl calling convention
  18. '       Used when calling non VB-friendly zLIB dll versions
  19. '   Alfred Koppold for his PNG, VB-only, decompression routines.
  20. '       Used when zLib & GDI+ not available
  21. '   Carles P.V for his pvResize logic
  22. '       Used when manually scaling images with NearestNeighbor or BiLinear interpolation
  23. '   www.zlib.net for their free zLIB.dll, the standard DLL for compressing/decompressing PNGs
  24. '       Without it, we'd be limited to GDI+ for creating PNGs
  25. '   coders like you that provide constructive criticism to make this class better & more all-inclusive
  26. '       Without your comments, this project probably would have died several versions/updates ago
  27. ' For most current updates/enhancements visit the following:
  28. '   Visit http://www.planetsourcecode.com/vb/scripts/ShowCode.asp?txtCodeId=67466&lngWId=1
  29.  
  30. ' = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
  31. '                                    O V E R V I E W
  32. ' = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
  33. ' About 32bpp pre-multiplied RGB (pARGB) bitmaps, if you are not aware.
  34. '   - These are used specifically for the AlphaBlend API & are GDI+ compatible
  35. '   Advantages:
  36. '       - Images can be per-pixel alpha blended
  37. '       - Opacity can be simultaneously adjusted during rendering
  38. '       - AlphaBlend does both BitBlt & StretchBlt for pARGB images.
  39. '       - Speed: AlphaBlend & GDI+ are pretty quick APIs vs manual blending
  40. '   Disadvantages:
  41. '       - The original RGB values are permanently destroyed during pre-multiplying
  42. '           -- Premultiplied formula: preMultipliedRed=(OriginalRed * Alpha) \ 255
  43. '           -- There is no way to convert pARGB back to non-premultiplied RGB values
  44. '              The formula would be: reconstructedRed=(preMultipliedRed * 255) \ Alpha.
  45. '               but because of integer division when pre-multiplying, the result is only
  46. '               close and if this should be premultiplied again & converted again, the
  47. '               alphas can get more transparent with every iteration.
  48. '               Fully opaque pixels & fully transparent pixels are not affected.
  49. '           ** Note: When images are converted to PNG formats, removal of
  50. '              premultiplication is performed to meet PNG specs.
  51. '       - Displaying a pre-multiplied bitmap without AlphaBlend will not result in
  52. '           the image being displayed as expected.
  53. '       - Not ideal for saving due to its size: SizeOf= W x H x 4
  54. '           -- better to save source image instead or compress the DIB bytes using favorite compression utility
  55. '           -- with GDI+ or zLib, image can be converted to PNG for storage
  56. '       - AlphaBlend (msimg32.dll) is not included/compatible with Win95, NT4 and lower
  57. '       - AlphaBlend on Win9x systems can be buggy, especially when rendering to DIBs vs DDBs
  58. ' Note that GDI+ is standard on WinXP+, and can be used on Win98,ME,2K, & on NT4 if SP6 is installed
  59.  
  60. ' ----------------------------------------------
  61. ' About Win95, Win98, NT3.5, NT4 & WinME support
  62. ' ----------------------------------------------
  63. ' The routines will not honor AlphaBlend if it exists on those systems. Win98's version,
  64. ' for example, has several bugs that can crash the application when AlphaBlending to DIBs.
  65. ' NT4, NT3.5 & Win95 do not come with AlphaBlend and I do not have WinME to test with.
  66. ' Therefore, to support these systems, the Render routine will alphablend manually
  67. ' regardless if the AlhpaBlend API (msimg32.dll) exists on the system or not.
  68.  
  69. ' Table of methods used for rendering dependent upon class settings and O/S
  70. ' ----------------------------------------------------------------------------------
  71. ' Win2K or Better?  GDI+ Available?  HighQualityInterpolation?  Method of Rendering
  72. '       Yes              Yes                No / Yes            AlphaBlend / GDI+
  73. '       No               Yes                No / Yes            GDI+ / GDI+
  74. '       Yes              No                 No / Yes            AlphaBlend / Manually
  75. '       No               No                 No / Yes            Manually / Manually
  76. ' Note that AlphaBlend does not support mirroring nor rotation nor high quality interpolation,
  77. ' so if these are applied when rendering, then class will use GDI+ if available,
  78. ' otherwise, manually rendered. By default, the class will initialize with
  79. ' HighQualityInterpolation=True if GDI+ is available.
  80. ' ----------------------------------------------------------------------------------
  81.  
  82. ' Class Purpose:
  83. ' This class holds the 32bpp image. It also marshals any new image thru
  84. ' the battery of parsers to determine best method for converting the image
  85. ' to a 32bpp alpha-compatible image. It handles rendering, rotating, scaling,
  86. ' mirroring of DIBs using manual processes, AlphaBlend, and/or GDI+.
  87. ' What about DirectX?  Hmmmm...
  88.  
  89. ' The parser order is very important for fastest/best results...
  90. ' cPNGparser :: will convert PNG, all bit depths; aborts quickly if not PNG
  91. ' cGIFparser :: will convert non-transparent/transparent GIFs; aborts quickly
  92. ' cICOpraser :: will convert XP-Alpha, paletted, true color, & Vista PNG icons
  93. '               -- can also convert most non-animated cursors
  94. ' cBMPparser :: will convert bitmaps, wmf/emf & jpgs
  95.  
  96. ' The parsers are efficient. Most image formats have a magic number that give
  97. '   a hint to what type of image the file/stream is. However, checks need to
  98. '   be employed because non-image files could feasibly have those same magic
  99. '   numbers. If the image is determined not to be one the parser is designed
  100. '   to handle, the parser rejects it and the next parser takes over.  The
  101. '   icon parser is slightly different because PNG files can be included into
  102. '   a Vista ico file. When this occurs, the icon parser will pass off the
  103. '   PNG format to the PNG parser automatically.
  104. ' And last but not least, the parsers have no advanced knowledge of the image
  105. ' format; as far as they are concerned, anything passed is just a byte array
  106.  
  107. ' = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
  108. '                                       CHANGE HISTORY
  109. ' = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
  110. ' Accompanying FAQ.rtf is updated with every change
  111. ' 3 Mar 07
  112. '   - Major bug realized.
  113. '       Thru trial and error, I have found that calling iparseIsArrayEmpty can generate
  114. '       "Expression Too Complex" errors in the routine that called that function. However, I
  115. '       cannot determine why and when this happens. It is an inconsistent error. The same O/S
  116. '       different PCs may or may not generate that error, but the iparseIsArrayEmpty is
  117. '       definitely involved. Therefore, I have rewritten that function and modified every
  118. '       line of code that calls that function.
  119. ' 2 Mar 07:
  120. '   - Bugs recognized & fixed
  121. '       - Using some zLib versions, PNG files may be much larger than expected. Fixed;
  122. '           -- the variable passed to zLib was not being updated with compressed size; ByVal,ByRef issue
  123. '           -- iparseValidateZLIB modified; could incorrectly identify calling convention for latest zLIB VB-version
  124. '           -- special thanx to Robert Rayment for helping troubleshooting this -- sorry for crashing your pc ;)
  125. '       - DIBs converted to palettized PNGs, without alpha, did not write the palette; fixed
  126. '       - WinME only. Manually rendering to WinME produced artifacts from the alpha channel; fixed
  127. '           -- modified Win9xBlend to use GetDIBits & SetDIBitsToDevice vs BitBlt; actually improved speed
  128. '           -- special thanx to Herman CK for helping troubleshoot this; I don't have WinME
  129. '       - This class' Initialize event corrected to positively identify Win2K and above.
  130. '   - Added 5 more grayscale options: RedMask, GreenMask, BlueMask, RedGreenMask, BlueGreenMask
  131. '       - Changed NTSC/PAL grayscale formula to be the default. See MakeGrayScale
  132. '   - Modified GetDIBbits to allow retrieval of non-premultiplied pixels
  133. '   - Modified SetDIBbits to accept either premultiplied or non-premultiplied pixels
  134. ' 27 Feb 07: by request
  135. '   - Added 3 supporting functions to extract DIB bytes into a passed array
  136. '       - GetDIBbits & SetDIBbits gets/sets DIB pixels
  137. '           -- parameters to return bytes in various formats/structures combinations
  138. '       - GetAlphaMask gets the DIB alpha values as an 8 byte/256 color, grayscale, array.
  139. ' 20 Feb 07:
  140. '   - PNGparser conversion routines overhauled for speed, minor error found & fixed
  141. '       -- PNGparser.InitializePalette did not correctly identify transparency index for Grayscale with simple transparency
  142. '   - PNGwriter.FormatCaption & FormatText recognized non-spec text but did not prevent it from being written to PNG
  143. '   - Modified PNGwriter to use zLIB compress2 function when available
  144. '   - Error on my part, last post had debugging code using zLibVB.dll vs zLib.dll
  145. '       -- no serious harm but versions prior to this update probably will not be able to use zlib.net's zLib.DLL
  146. ' 18 Feb 07:
  147. '   - Bugs recognized & fixed
  148. '       -- cPNGwriter.OptimizeTrueColor could error when converting to 24bpp images
  149. '       -- cPNGwriter.OptimizeTrueColor was not writing the single transparency color for 24bpp converted images
  150. '       -- cPNGwriter.Write_tRNS was not always writing the tranpsarency color either
  151. '       -- PngPropertySet was not honoring the user-selected filterMethod property
  152. ' 16 Feb 07:
  153. '   - More PNG support....(First non-GDI+ PNG writer in VB open source? Maybe.)
  154. '       -- Added cPNGwriter class. Can create PNGs using zLIB.dll versions. See class for more
  155. '       -- Added cCDECL class. Allows calling zLIB.dll when zLIB is not VB-friendly
  156. '           -- added modParsers.iparseValidateZLIB to determine if zLIB is available & if VB-friendly
  157. '           -- required adding some custom zLIB calls to end of cPngWriter & cPngParser classes
  158. '       -- added PngPropertySet to allow PNG creation options not possible w/GDI+. Must have zLIB available
  159. '       -- added PngPropertyGet to retrieve settings. Over a dozen options
  160. '       -- added isZlibEnabled property to inform you if zLIB can be used or not
  161. '       -- Modified SaveToStream_PNG & SaveToFile_PNG to use zLIB if GDI+ is not available,
  162. '               but zLIB is or vice versa. zLIB is prefered when pngPropertySet is called
  163. '       -- Zlib is 100% free and is available directly from source: www.zlib.net
  164. ' 11 Feb 07:
  165. '   - Logic error. When a DIB is first initialized, the Alpha property is False.
  166. '       This should have been Alpha=True. Note that if you are creating blank DIBs and rendering other
  167. '       DIBs to the blank one, you should change the blank DIB's alpha and image format properties as
  168. '       appropriate, dependent upon what you are rendering to that DIB. The Alpha property is used in
  169. '       other routines and must be accurate, but the ImageType property is not used
  170. '   - Added imgError to the ImageType property enumeration. This can assist when self-rendering
  171. '       DIBs. If ImageType=imgError then Handle=0& and no DIB has been loaded into the class.
  172. ' 10 Feb 07:
  173. '   - Added LoadPicture_FromOrignalFormat routine which will recreate the DIB from the bytes
  174. '       cached during a call to LoadPicture_File or LoadPicture_Stream
  175. '   - Added TrimImage routine which will remove excess transparency from an image
  176. '       If a 256x256 image has 20x20 transparency border around it, the image will be reduced to 216x216
  177. '   - When calling Resize, class would not save original image bytes if they existed; now it does
  178. '   - Minor tweaks in rotation routines. Routines no longer overwrite class' Interpolation setting
  179. '   - Logic error fixed: GDI+ when rendering mirrored & rotated used incorred DC X,Y coordinates
  180. ' 4 Feb 07:
  181. '   - Added SaveToFile_PNG & SaveToStream_PNG as main class options, but only supported if isGDIplusEnabled = True
  182. '   - Complete revamp of mirroring routines.
  183. '       -- Added MirrorDIB routine that mirrors an image as needed & mirrored bytes are later rotated, scaled, rendered
  184. '       -- Previous version attempted to calculate mirroring offsets when scaling, rotating, rendering -- failed
  185. '       -- Following routines modified: pvResize, CopyImageTo, Resize, RotateAtTopLeft
  186. '   - Logic error fixed: pvResize would clip wrong end of image when image is rendered past vertical bounds of DC.
  187. '   - Modified startup to always set HighQualityInterpolation if GDI+ is available.
  188. ' 1 Feb 07: By request...
  189. '   - Added mirroring support to following routines. Passing a negative destination width and/or height causes mirroring
  190. '       - pvResize, Win9xBlend, CopyImageTo, Resize, RotateAtCenterPoint, RotateAtTopLeft & cGDIPlus.RenderGDIplus
  191. '       - The msimg32.dll AlphaBlend API cannot perform mirroring. Therefore...
  192. '       - Whenever mirroring is in effect and GDI+ can't be used, mirroring will be done manually
  193. '       - GDI+, if available, will only perfrorm the mirroring if also rotating or if HighQualityInterpolation=True
  194. '   - Found another minor bug. Broke GDI+ ability to Global blend while rotating. Fixed.
  195. ' 31 Jan 07:
  196. '   - Fixed logic error when rotating negative angles via GDI+ (cGDIPlus.RenderGDIplus routine)
  197. '   - Fixed logic error when manually resizing using BiLinear method (pvResize routine)
  198. '       - routines were combining current pixel with one above, not below as required
  199. '   - Fixed rotation routines (non-GDI+); now rotation while non-proportional scaling compatible
  200. '   - Renamed cPNGParser.SaveTo routine to cGDIPlus.SaveToPNG. See Change 4Jan07 below for more
  201. ' 30 Jan 07:
  202. '   - Added rotation options. See RotateAtCenterPoint & RotateAtTopLeft
  203. '       - The two routines are identical except for how the destination X,Y coords are determined
  204. '   - Added isGDIplusEnabled property to inform you whether or not GDI+ can be used on the system
  205. '   - Added HighQualityInterpolation property to produce better renderings
  206. '       - When set to True & GDI+ is available, any rendering is done by GDI+
  207. '       - When set to True and GDI+ is not available, manual interpolation is done when scaling/rotating
  208. '       - Property can be set to False manually to prevent GDI+ usage
  209. '   - Added MakeGrayScale routine. Irreversible pixel modifications
  210. '       - 3 different grayscale formulas are provided
  211. '   - Relocated all GDI+ function calls and related code into a new class: cGDIPlus
  212. '   - Relocated cPNGparser.ValidateDLL to modParsers as iparseValidateDLL
  213. ' 25 Jan 07:
  214. '   - Modified Win9xBlend routine. Did not exactly replicate AlphaBlend when stretching; fixed I believe
  215. '       -- Added extra checks in Win9xBlend & pvResize when alphablending on Win9x systems.
  216. '       -- Prevents user from supplying invalid values that could cause routines to read past allocated memory
  217. '       -- Properly handles negative destination DC offsets
  218. '   - Changed iswin95Alpha property to isAlphaBlendFriendly to indicate whether or not AlphaBlend will be used
  219. ' 24 Jan 07:
  220. '   - Now compatible with all O/S. Added Win95/NT4 support to the following routines:
  221. '       CopyImageTo, Resize, Render
  222. '       -- Added Win9xBlend & heavily modified then added Carles P.V.'s pvResize routine
  223. '   - Bug found. cPNGparser.vbDecompress, under NT4, was causing crashes when trying to
  224. '       resize a passed byte array. Fixed. Array is sized before it is passed to that routine
  225. '   - Bug found. The iparseCreateShapedRegion routine was creating shaped regions bottom up
  226. '       and this crashed on NT4. Fixed so regions are created top down always
  227. '   - Bug found. In Win98 & possibly other O/S. When VB creates a 24bpp stdPicture as used
  228. '       in cBMPparser, the stdPicture.Render method can write into the alpha channel of the
  229. '       destination 32bpp DIB; 24bpp has no alpha channel. Routine tweaked to handle that.
  230. ' 17 Jan 07:
  231. '   - Added CreateCheckerBoard method. This method will create a checkerboard pattern
  232. '       as the DIB image. It will also set the ImageType property to imgCheckerBoard
  233. '       so you know whether or not the image is class checkerboard or not.
  234. '       This can be useful when the DIB should be displayed, but has no image to display.
  235. '       The flag can be used to determine saving the image. If imgCheckerboard then noSave
  236. '   - Added Resize method to permanently resize the image within the DIB
  237. '   - Added optional resizing parameters to CopyImageTo routine
  238. '   - Tweaked cBMPparser & cGIFparser to always modify alpha bytes regardless of transparency
  239. '       -- Previously, when image had no transparency, the alpha bytes were not touched, rather
  240. '          the class tracked this information via its Alpha property. But if you wanted to pass
  241. '          the DIB to some other routine in your project and process/render it, the unmodified
  242. '          alpha bytes could prove to fool those processes/routines
  243. '   - Tweaked Render method to fully expose all of AlphaBlend's parameters
  244. '   - LoadPicture_StdPicture could not process WMFs, fixed
  245. '   - LoadDIBinDC fixed - could fail if multiple calls made passing a True parameter
  246. '   - Error in LoadPictureEx prevented saving image bytes when PNG file was loaded, fixed
  247. ' 5 Jan 07:
  248. '   - Added SaveFormat parameter to LoadPicture_File & LoadPicture_Stream
  249. '       -- option has class cache the original bytes of the image if loaded
  250. '       -- the 32bpp DIB will always be larger than the source bytes and for
  251. '           usercontrols, saving the original bytes takes less space than
  252. '           saving the DIB bytes.
  253. '   - Added GetOrginalFormat to retrieve bytes when SaveFormat was passed as True
  254. '   - Added SetOriginalFormat used when copying one DIB class to another
  255. ' 4 Jan 07:
  256. '   - Added LoadPicture_ByHandle, LoadPicture_StdPicture, ScaleImage & CopyImageTo
  257. '   - Added cGDIPlus.SaveToPNG (testing). Requires GDI+ or zLIB but will save 32bpp to PNG file or stream
  258. '       -- not accessible, right now, from c32bppDIB. Must create cGDIPlus class to use it.
  259. '   - Modified cICOparser's GetBestMatch algorithm
  260. '   - Added imgPNGicon as an image type to distinguish PNG in Vista Icon vs standard .PNG file
  261. '   - Bug found: removing overlays in cGIFparser.ConvertGIFto32bpp; forgot ByVal VarPtrArray(...)
  262. '       which could cause crash when compiled. Fixed & double checked everywhere else too
  263. ' 1 Jan 07:
  264. '   - Added SaveToFile & SaveToStream methods
  265. '   - cBMPparser could possibly try to query unauthorized memory; fixed
  266. '   - Methodology changed a bit when parsers return results. If image is definitely one
  267. '       that the parser is responsible for & the image is invalid, the parser will return
  268. '       True to prevent other parsers from handling the image. The c32bppDIB.Handle is used
  269. '       to determine true success or failure.
  270. '       -- cGIFparser when recognizing improperly formatted GIF would allow image to continue to
  271. '           other parsers which then may cause those parsers to lock up.
  272. ' 26 Dec 06: First version
  273. ' = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
  274.  
  275.  
  276. ' No APIs are declared public. This is to prevent possibly, differently
  277. ' declared APIs, or different versions of the same API, from conflciting
  278. ' with any APIs you declared in your project. Same rule for UDTs.
  279. ' Note: I did take liberties, changing parameter types, in several APIs throughout
  280.  
  281. ' Used to determine operating system
  282. Private Declare Function GetVersionEx Lib "kernel32" Alias "GetVersionExA" (lpVersionInformation As Any) As Long
  283. Private Const VER_PLATFORM_WIN32_WINDOWS As Long = &H1&
  284. Private Type OSVERSIONINFOEX
  285.    dwOSVersionInfoSize As Long
  286.    dwMajorVersion As Long
  287.    dwMinorVersion As Long
  288.    dwBuildNumber As Long
  289.    dwPlatformId As Long
  290.    szCSDVersion As String * 128 ' up to here is OSVERSIONINFO vs EX
  291.    wServicePackMajor As Integer ' 8 bytes larger than OSVERSIONINFO
  292.    wServicePackMinor As Integer
  293.    wSuiteMask As Integer
  294.    wProductType As Byte
  295.    wReserved As Byte
  296. End Type
  297.  
  298. ' APIs used to manage the 32bpp DIB
  299. Private Declare Sub CopyMemory Lib "kernel32.dll" Alias "RtlMoveMemory" (ByRef Destination As Any, ByRef Source As Any, ByVal Length As Long)
  300. Private Declare Function CreateCompatibleDC Lib "gdi32.dll" (ByVal hdc As Long) As Long
  301. Private Declare Function GetDC Lib "user32.dll" (ByVal hwnd As Long) As Long
  302. Private Declare Function ReleaseDC Lib "user32.dll" (ByVal hwnd As Long, ByVal hdc As Long) As Long
  303. Private Declare Function DeleteDC Lib "gdi32.dll" (ByVal hdc As Long) As Long
  304. Private Declare Function SelectObject Lib "gdi32.dll" (ByVal hdc As Long, ByVal hObject As Long) As Long
  305. Private Declare Function DeleteObject Lib "gdi32.dll" (ByVal hObject As Long) As Long
  306. Private Declare Function CreateDIBSection Lib "gdi32.dll" (ByVal hdc As Long, ByRef pBitmapInfo As Any, ByVal un As Long, ByRef Pointer As Long, ByVal Handle As Long, ByVal dw As Long) As Long
  307. Private Declare Function AlphaBlend Lib "msimg32.dll" (ByVal hdcDest As Long, ByVal nXOriginDest As Long, ByVal nYOriginDest As Long, ByVal nWidthDest As Long, ByVal nHeightDest As Long, ByVal hdcSrc As Long, ByVal nXOriginSrc As Long, ByVal nYOriginSrc As Long, ByVal nWidthSrc As Long, ByVal nHeightSrc As Long, ByVal lBlendFunction As Long) As Long
  308. Private Declare Function SetStretchBltMode Lib "gdi32.dll" (ByVal hdc As Long, ByVal nStretchMode As Long) As Long
  309. Private Declare Function GetObjectType Lib "gdi32.dll" (ByVal hgdiobj As Long) As Long
  310. Private Declare Function GetCurrentObject Lib "gdi32.dll" (ByVal hdc As Long, ByVal uObjectType As Long) As Long
  311. Private Declare Function GetIconInfo Lib "user32.dll" (ByVal hIcon As Long, ByRef piconinfo As ICONINFO) As Long
  312. Private Declare Function SetDIBitsToDevice Lib "gdi32.dll" (ByVal hdc As Long, ByVal X As Long, ByVal Y As Long, ByVal dX As Long, ByVal dY As Long, ByVal SrcX As Long, ByVal SrcY As Long, ByVal Scan As Long, ByVal NumScans As Long, ByRef Bits As Any, ByRef BitsInfo As BITMAPINFO, ByVal wUsage As Long) As Long
  313. Private Declare Function GetDIBits Lib "gdi32.dll" (ByVal aHDC As Long, ByVal hBitmap As Long, ByVal nStartScan As Long, ByVal nNumScans As Long, ByRef lpBits As Any, ByRef lpBI As BITMAPINFO, ByVal wUsage As Long) As Long
  314. Private Const STRETCH_HALFTONE As Long = &H4&
  315. Private Const OBJ_BITMAP As Long = &H7&
  316. Private Const OBJ_METAFILE As Long = &H9&
  317. Private Const OBJ_ENHMETAFILE As Long = &HD&
  318.  
  319. ' APIs used to create files
  320. Private Declare Function CreateFile Lib "kernel32" Alias "CreateFileA" (ByVal lpFileName As String, ByVal dwDesiredAccess As Long, ByVal dwShareMode As Long, lpSecurityAttributes As Any, ByVal dwCreationDisposition As Long, ByVal dwFlagsAndAttributes As Long, ByVal hTemplateFile As Long) As Long
  321. Private Declare Function WriteFile Lib "kernel32" (ByVal hFile As Long, lpBuffer As Any, ByVal nNumberOfBytesToWrite As Long, lpNumberOfBytesWritten As Long, lpOverlapped As Any) As Long
  322. Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
  323. Private Const INVALID_HANDLE_VALUE = -1&
  324. Private Const CREATE_ALWAYS = &H2&
  325. Private Const GENERIC_READ = &H80000000
  326. Private Const GENERIC_WRITE = &H40000000
  327. Private Const FILE_ATTRIBUTE_NORMAL = &H80&
  328.  
  329. ' used to create the checkerboard pattern on demand
  330. Private Declare Function FillRect Lib "user32.dll" (ByVal hdc As Long, ByRef lpRect As RECT, ByVal hBrush As Long) As Long
  331. Private Declare Function CreateSolidBrush Lib "gdi32.dll" (ByVal crColor As Long) As Long
  332. Private Declare Function OffsetRect Lib "user32.dll" (ByRef lpRect As RECT, ByVal X As Long, ByVal Y As Long) As Long
  333. Private Type RECT
  334.     Left As Long
  335.     Top As Long
  336.     Right As Long
  337.     Bottom As Long
  338. End Type
  339.  
  340. ' used when saving an image or part of the image
  341. Private Declare Function VarPtrArray Lib "msvbvm60.dll" Alias "VarPtr" (Ptr() As Any) As Long
  342. Private Type SafeArrayBound
  343.     cElements As Long
  344.     lLbound As Long
  345. End Type
  346. Private Type SafeArray
  347.     cDims As Integer
  348.     fFeatures As Integer
  349.     cbElements As Long
  350.     cLocks As Long
  351.     pvData As Long
  352.     rgSABound(0 To 1) As SafeArrayBound ' reusable UDT for 1 & 2 dim arrays
  353. End Type
  354.  
  355. Private Type ICONINFO
  356.     fIcon As Long
  357.     xHotspot As Long
  358.     yHotspot As Long
  359.     hbmMask As Long
  360.     hbmColor As Long
  361. End Type
  362. Private Type BITMAPINFOHEADER
  363.     biSize As Long
  364.     biWidth As Long
  365.     biHeight As Long
  366.     biPlanes As Integer
  367.     biBitCount As Integer
  368.     biCompression As Long
  369.     biSizeImage As Long
  370.     biXPelsPerMeter As Long
  371.     biYPelsPerMeter As Long
  372.     biClrUsed As Long
  373.     biClrImportant As Long
  374. End Type
  375. Private Type BITMAPINFO
  376.     bmiHeader As BITMAPINFOHEADER
  377.     bmiPalette As Long
  378. End Type
  379.  
  380. '// Added by Bryan Utley
  381.  
  382. Private Type RGBQUAD
  383.     B           As Byte
  384.     G           As Byte
  385.     R           As Byte
  386.     A           As Byte
  387. End Type
  388.  
  389. Private Type SAFEARRAY2D
  390.     cDims       As Integer
  391.     fFeatures   As Integer
  392.     cbElements  As Long
  393.     cLocks      As Long
  394.     pvData      As Long
  395.     Bounds(1)   As SafeArrayBound
  396. End Type
  397.  
  398. '// --------------------------
  399.  
  400.  
  401. Private Const AC_SRC_OVER = &H0&
  402. Private Const AC_SRC_ALPHA = &H1&
  403.  
  404. Public Enum eImageFormat    ' source image format
  405.     imgError = -1  ' no DIB has been initialized
  406.     imgNone = 0    ' no image loaded
  407.     imgBitmap = 1  ' standard bitmap or jpg
  408.     imgIcon = 3    ' standard icon
  409.     imgWMF = 2     ' windows meta file
  410.     imgEMF = 4     ' enhanced WMF
  411.     imgCursor = 5  ' standard cursor
  412.     imgBmpARGB = 6  ' 32bpp bitmap where RGB is not pre-multiplied
  413.     imgBmpPARGB = 7 ' 32bpp bitmap where RGB is pre-multiplied
  414.     imgIconARGB = 8 ' XP-type icon; 32bpp ARGB
  415.     imgGIF = 9      ' gif; if class.Alpha=True, then transparent GIF
  416.     imgPNG = 10     ' PNG image
  417.     imgPNGicon = 11 ' PNG in icon file (Vista)
  418.     imgCursorARGB = 12 ' alpha blended cursors? do they exist yet?
  419.     imgCheckerBoard = 64 ' image is displaying own checkerboard pattern; no true image
  420. End Enum
  421.  
  422. Public Enum ePngProperties ' following are recognized "Captions" within a PNG file
  423.     txtTitle = 1           ' See cPNGwriter.SetPngProperty for more information
  424.     txtAuthor = 2
  425.     txtDescription = 4
  426.     txtCopyright = 8
  427.     txtCreationTime = 16
  428.     txtSoftware = 32
  429.     txtDisclaimer = 64
  430.     txtWarning = 128
  431.     txtSource = 256
  432.     txtComment = 512
  433.     ' special properties
  434.     txtLargeBlockText = 1024 ' this is free-form text can be of any length & contain most any characters
  435.     dateTimeModified = 2048  ' date/time of the last image modification (not the time of initial image creation)
  436.     colorDefaultBkg = 4096   ' default background color to use if PNG viewer does not do transparency
  437.     filterType = 8192        ' one of the eFilterMethods values
  438.     ClearAllProperties = -1  ' resets all PNG properties
  439. End Enum
  440.  
  441. Public Enum eTrimOptions    ' see TrimImage method
  442.     trimAll = 0             ' can be combined using OR
  443.     trimLeft = 1
  444.     trimTop = 2
  445.     trimRight = 4
  446.     trimBottom = 8
  447. End Enum
  448.  
  449. Public Enum eScaleOptions   ' See ScaleImage method
  450.     scaleToSize = 0         ' [Default] will always scale
  451.     scaleDownAsNeeded = 1   ' will only scale down if image won't fit
  452.     ScaleStretch = 2        ' wll always stretch/distort
  453. End Enum
  454.  
  455. Public Enum eGrayScaleFormulas
  456.     gsclNTSCPAL = 0     ' R=R*.299, G=G*.587, B=B*.114 - Default
  457.     gsclCCIR709 = 1     ' R=R*.213, G=G*.715, B=B*.072
  458.     gsclSimpleAvg = 2   ' R,G, and B = (R+G+B)/3
  459.     gsclRedMask = 3     ' uses only the Red sample value: RGB = Red / 3
  460.     gsclGreenMask = 4   ' uses only the Green sample value: RGB = Green / 3
  461.     gsclBlueMask = 5    ' uses only the Blue sample value: RGB = Blue / 3
  462.     gsclRedGreenMask = 6 ' uses Red & Green sample value: RGB = (Red+Green) / 2
  463.     gsclBlueGreenMask = 7 ' uses Blue & Green sample value: RGB = (Blue+Green) / 2
  464. End Enum
  465.  
  466. Public Enum eFilterMethods
  467.     filterDefault = 0     ' paletted PNGs will use filterNone while others will use filterPaeth
  468.     filterNone = 1        ' no byte preparation used; else preps bytes using one of the following
  469.     filterAdjLeft = 2     ' see cPNGwriter.EncodeFilter_Sub
  470.     filterAdjTop = 3      ' see cPNGwriter.EncodeFilter_Up
  471.     filterAdjAvg = 4      ' see cPNGwriter.EncodeFilter_Avg
  472.     filterPaeth = 5       ' see cPNGwriter.EncodeFilter_Paeth
  473.     filterAdaptive = 6    ' this is a best guess of the above 4 (can be different for each DIB scanline)
  474. End Enum
  475.  
  476. Private m_PNGprops As cPNGwriter    ' used for more advanced PNG creation options
  477. Private m_StretchQuality As Boolean ' if true will use BiLinear or better interpolation
  478. Private m_Handle As Long        ' handle to 32bpp DIB
  479. Private m_Pointer As Long       ' pointer to DIB bits
  480. Private m_Height As Long        ' height of DIB
  481. Private m_Width As Long         ' width of DIB
  482. Private m_hDC As Long           ' DC if self-managing one
  483. Private m_prevObj As Long       ' object deselected from DC when needed
  484. Private m_osCAP As Long         ' 1=Can use AlphaBlend (Win2K+), 2=Can use GDI+ (Win98+), 4=Can use zLib. See Class_Initialize
  485. Private m_Format As eImageFormat ' type of source image
  486. Private m_ManageDC As Boolean   ' does class manage its own DC
  487. Private m_AlphaImage As Boolean ' does the DIB contain alpha/transparency
  488. Private m_ImageByteCache() As Byte  ' should you want the DIB class to cache original bytes
  489. ' ^^ N/A if image is loaded by handle, stdPicture, or resource
  490.  
  491. Public Function LoadPicture_File(ByVal FileName As String, _
  492.                                 Optional ByVal iconCx As Long, _
  493.                                 Optional ByVal iconCy As Long, _
  494.                                 Optional ByVal SaveFormat As Boolean) As Boolean
  495.  
  496.     ' PURPOSE: Convert passed image file into a 32bpp image
  497.     
  498.     ' Parameters.
  499.     ' FileName :: full path of file. Validation occurs before we continue
  500.     ' iconCx :: desired width of icon if file is an icon file. Default is 32x32
  501.     ' iconCy :: desired height of icon if file is an icon file. Default is 32x32
  502.     ' SaveFormat :: if true, then the image will be cached as a byte array only
  503.     '   if the image was successfully loaded. Call GetOrginalFormat to retrieve them.
  504.     
  505.     ' Why would you want to save the bytes? If this is being used in a usercontrol,
  506.     ' saving the bytes will almost always be less size than saving the 32bit DIB.
  507.     ' Additionally, these classes have the ability to get different sizes from
  508.     ' the original source (i.e., WMF, icon, cursors) if available, but if the
  509.     ' 32bit DIB is saved, it is a constant size. The potential of different sizes
  510.     ' could allow better resizing of the image vs stretching the DIB.
  511.  
  512.     On Error Resume Next
  513.     If Not iparseFileExists(FileName) Then Exit Function
  514.     If FileLen(FileName) < 57 Then Exit Function
  515.     ' no image file/stream can be less than 57 bytes and still be an image
  516.     If Err Then
  517.         Err.Clear
  518.         Exit Function
  519.     End If
  520.     Dim aDIB() As Byte  ' dummy array
  521.     LoadPicture_File = LoadPictureEx(FileName, aDIB(), iconCx, iconCy, 0&, 0&, SaveFormat)
  522.     
  523. End Function
  524.  
  525. Public Function LoadPicture_Stream(inStream() As Byte, _
  526.                                     Optional ByVal iconCx As Long, _
  527.                                     Optional ByVal iconCy As Long, _
  528.                                     Optional ByVal streamStart As Long = 0&, _
  529.                                     Optional ByVal streamLength As Long = 0&, _
  530.                                     Optional ByVal SaveFormat As Boolean) As Boolean
  531.     
  532.     ' PURPOSE: Convert passed array into a 32bpp image
  533.     
  534.     ' Parameters.
  535.     ' inStream:: byte stream containing the image. Validation occurs below
  536.     ' iconCx :: desired width of icon if file is an icon file. Default is 32x32
  537.     ' iconCy :: desired height of icon if file is an icon file. Default is 32x32
  538.     ' streamStart :: array position of 1st byte of the image file. Validated.
  539.     ' streamLength :: total length of the image file. Validated.
  540.     ' SaveFormat :: if true, then the image will be cached as a byte array only
  541.     '   if the image was successfully loaded. Call GetOrginalFormat to retrieve them.
  542.     
  543.     ' Why would you want to save the bytes? If this is being used in a usercontrol,
  544.     ' saving the bytes will almost always be less size than saving the 32bit DIB.
  545.     ' Additionally, these classes have the ability to get different sizes from
  546.     ' the original source (i.e., WMF, icon, cursors) if available, but if the
  547.     ' 32bit DIB is saved, it is a constant size. The potential of different sizes
  548.     ' could allow better resizing of the image vs stretching the DIB.
  549.     
  550.     If iparseIsArrayEmpty(VarPtrArray(inStream)) Then Exit Function
  551.     If streamStart < LBound(inStream) Then streamStart = LBound(inStream)
  552.     If streamLength = 0& Then streamLength = UBound(inStream) - streamStart + 1&
  553.     If streamLength < 57 Then Exit Function
  554.     ' no image file/stream can be less than 57 bytes and still be an image
  555.     LoadPicture_Stream = LoadPictureEx(vbNullString, inStream, iconCx, iconCy, streamStart, streamLength, SaveFormat)
  556.  
  557. End Function
  558.  
  559. Public Function LoadPicture_Resource(ByVal ResIndex As Variant, ByVal resSection As Variant, _
  560.                             Optional VbGlobal As IUnknown, _
  561.                             Optional ByVal iconCx As Long, _
  562.                             Optional ByVal iconCy As Long, _
  563.                             Optional ByVal streamStart As Long = 0&, _
  564.                             Optional ByVal streamLength As Long = 0&) As Boolean
  565.  
  566.     ' PURPOSE: Convert passed resource into a 32bpp image
  567.     
  568.     ' Parameters.
  569.     ' ResIndex :: the resource file index (i.e., 101)
  570.     ' ResSection :: one of the VB LoadResConstants or tion An01)gng, Bon  orY'class fh As Lhanage its owl ResInffect and GDhandrev, _
  571.          lass fh A a lass fh Abyten:bType = fect VQ, 10n Exit GDhandrev,          = &H As f the Vs BitBly woulyVal Re 0&,being use          =ds(1)   As SafeArrayBound
  572. End Typen loWay
  573.   te
  574. hed as a byte array on nd TClAGrian is an icon file. Default itch =uage fsto a 32bpp image.bHue, thedrev,          = &H As fte array on n  = &l ByVal streaf-managing one
  575. Private m_S  
  576.     ' PURPOSE: Convert passed array into an image
  577. '    C7       NERIC_W
  578.     If FileLen(FilemIB's alleavcwg
  579.     3rL<7    wleam)ndows mVrocwglue: Rss2.dll"            esults. If 'O f the Vs BitBly woulyVal  0         k       k       xByVau esuSE: Cooarray oTc
  580. Prsion
  581.  
  582. Public Function LoadPicture_Stream(inStream(eImage method
  583.     scaleToSizaving tinStream(eImndex A e = 0    ' nsourcn :: one ofam(eImndess size than saviyublic osave the bytes? If this than 57 thaomhaomhaomhao df thiblic osave thegth As Lo than saviyubli_g system
  584. Pra
  585.  
  586. Pusf an ic-1&
  587. Private Const Cm Declare +,Load&x.d then added CIdess sNded by PURPsan saviyublinaltandard cursor
  588.     imgBmpARGB = 6 some hiblic oA +,Load&x.d theny the RetType property      C7geTo, Resize, Render
  589. '       -- Added Win9xBlend & heavily modified then added g      lN=ng
  590.     cLoetReoule
  591.  
  592. End Funodified then added g     o _
  593.         s.
  594. &ofceFilte[ldeoule
  595.  
  596.  
  597.  
  598.  
  599.  
  600.  
  601.  
  602.  
  603.  
  604.  
  605.  
  606.  
  607.  
  608.  
  609.  
  610.  
  611. e Const OBJ_ENHMETAFILE Aaession Ast generate that error, bn added s Long
  612. End Type
  613. Private Type Long
  614. d is just a by0000
  615. P
  616.  
  617.  
  618.  
  619.  
  620.  
  621.  
  622. e Fun,- added P-enMask
  623. '       - Chang R=R*.t Saf ParametSderen lo:ehao dfearAllProperties = -1  ' ureEY     he Vs BitBly wove  is an icon es
  624.    e  is   is   iseam(et to retri5    is   iseam(et tOi is just a by0000
  625. P
  626. s just a by00000
  627. P
  628. s C'      
  629. P
  630. s just a by0l" Alias "RtlMoveMemors   iseam(et  savD p Aliasity to Global .  BitBly wove  is aaaaaaaaaaaaaaaalte[ldoFun,eaaaimgEMF = 4     ' enhanced WMF
  631.   ccurs beforeh = odn: CooarradoFs5omhaomhanst OBJ_ENHMMF = 4      mhanst OB't fit
  632.     ScaleSn OffsetRect Lieis   isea classes have the abili'e adve im as ByteclafvObj sn loW<SbStar= 4  (eIaes? If this than 57 thaomhaomhaomhao df aessaaaa saaaa = 11 '  beforeh = odn:1 '  be"ing the DIB byt image vs stretcaIf thS[meter
  633. '   - Er =ds(1)    stdPicture, or resSderen lo:ehao dfearAllProperties = -1  ' ure,
  634. ' r=EsrderefearAlVal iconCy At to retri5 rAlVal iconCys Long, ByV= 4  (es when trying to
  635. '       resize a passed byte array. Fixed. Ahen ryV= 4  (es. Fixed.n loW<ght causes micon fgay. Fixed. Ahen r, when parsearAllProourceixeFixed. 
  636.     3rL<7    wl Fixed.n loture 
  637. P
  638. s just a bt tue tional BhAFparser.ConvertGIFxeFixed. 
  639.       wl Fixedfonve,t tumst a bnalFpl BEpl BEpl BEpl BEpl BEpl B)DnStreamWle, bP
  640. snStsle, bPulyValoust a by0000
  641. P
  642.  
  643.  
  644.  
  645.  
  646.  
  647.  
  648. e Fun,- added P-enMask
  649. '    true, thenT.he bytes will almost always be less size than saving the 32bit DIB.
  650.     ' Additionally, these classes have the ability to get different sizes from
  651.     ' the origiiiiBue, thenT.heal resSection s from
  652. , iconCx, ik
  653. '    tra'
  654. , i = -1  ' no DIBrwizes or rrhp = -1  ' uro( Decl=&1rNObj As Long  DertGIFO 'O f the Vsd2bpp image Vsd2bze l wUsodiffered2bpp image Vsd2bze l wUso
  655. 2nnel; fi  destib path of file. Valie Vshese clib pa.x As cPNGwas jao dfearAllPiSjao dieT1your ib paarsByVainitialized, th     -- se clib paByVa he imag Addit
  656.  
  657.  
  658.  
  659.  
  660.  
  661. e ScaleSn OfVa hetainitializGrian is an ib lessn Of
  662.  5 OfVa hetOe intIcon = 3    emIB' source (i.e., W     , W   Iconr/HMMF = W   oill. However, c a buro( Decl c a buro( Dng * 12   oill. However, Icon = rhp oweveruhers stretcLong, _
  663.        rffecxeated.
  664. 2bpp image.bHue, thedr, _
  665.        hedr, _= odn:&l ByValker to always modifes m.Epl BEpl B)DnS-1  ' uro( Decl=&1rNObj As Long  DertGIFO 'O f the Vsd2bpp image Vsd2bze l wUsodiffered2bpp image Vsd2bze l wUso
  666. 2nnel; fi  destib path of file. Valie Vshese clib pa.x As cPNGwasas jae array. nCx, outwhen pre, theed resource into a 32bpp image
  667.   d:hods vacPNGwas jao djao dieT1your2bze            Optional VbGlobaAiginal bytes
  668. ' ^^ee&ways modifeslend &nal bytes
  669. ' ^^ee&bGlobaAent si'caleStretch 2pe
  670. d2bze l wUso
  671. 2nnel; fi  destib path of 'modicePackMajst /onal By DeclFpl BEpPmat :: if = -1valid, l
  672.     Boetch 2peA ByValker tomage Vsd2bze l wUso
  673. 2nnel; fi  destib path of file. Valie Vshese clib pa.x As cPNGwas jao dfearAllPiSjao dieT1your ib paarsByVainitialized, th     -- se clib paByVa he imag Addit
  674.  
  675.  
  676.  
  677.  
  678.  
  679. e ScaleSn OfVa hetainit DeclFpl BEpPmath     -- s8it DeclFpl BE -- se not.
  680. '       This can 
  681. Pubd'      k    y0000
  682. oxlFpl BE -Cal icsd2bzzzzzzzzz1oed Wiral icsd2bzzzzzze les is saved, isd2b, oud2bzzzzzzzzz1oed Wiral icsd2bzzzs saved, isddal icsd2bdis is aIB byt image vs stretcn samplzzzzzzbzzz is aIB by000 stretcn samplzzzzzzbzzz is aIB by000 stretcn saIi
  683. End Type
  684.  
  685. Private Type SAFEARRAY2D
  686.     cDimhe checkerboard pioType SckerbF
  687.   cczzz1oed WiralpsCP(redone o2bdis is ae vs stoTyreWb       and this cesouttbze l wUso
  688. 2nnel;s Bo
  689.     ' Pard pioTypei_
  690.       ot < LBound(inStctucn(cti  Deresource inodiffer  true, thenT.URPOSE: CondicePackMajst /onal By DeclFpl BEpPmat :: if = -
  691.     i:: .QT As Boolean
  692.     
  693.     ' d    e bytsfnctucn(cti  Deresounct;   rtg  imgCheclPmaG,p9
  694.  
  695.  
  696.  
  697. ,zz1oed resource inTomhanst OBJ_ENHMMF = 4 Additiozs saved, Checllare Function Fillz1oRer.ConvertGIFxeFixed. 
  698.  rFPngProperty d as a (nCy :: deste
  699.     R       e0ze caGIFxeFixed.1oRer.ConvertGuxENHMMF = 4 Additioz, _
  700.  4ertGIFonal - Er =caGIFzzz1oeds ae vs stoTyreWbIFzzz1Ayl"        
  701.  4erPPPPPe0ze caGIFxeA4erPPPPPdded by Bryan Utleyee
  702.   iplied pm(eImageWbIFzzz1AyoeFix)s1Ayl"      =As Lone&bGlo1Ayl"        If thph As Lhanage its owl Re d    ety tpr&outtbze l wUso
  703. 2nnel;s Bo
  704.   usesxong, l; f = = te invD p Aliasity to Globaltl /sity to Globaltl /sity to invD p Aliasit. nCCm Declare +,Load&x.d thenE    -tGIFO 'O fem Declare +,Load ^^ N/A if image is loaded by handle, stdPicture, or reso  destib pattAuthor
  705.   32bpp ARGB N/A if image is loaded by handle, stdPicturrunctre       
  706.  4erPloaded by han[ldoFulGreenMf iIFxeA4erPes?l; f = = tLoadnalRg iplie+at erfearAllProperties = -1  Red+Green) / outwhen pre, theed resource into a 32bpp image
  707.   d:hods vacPNGwas jao djao dieT1youfilterDefaus jao djao dieT1Xdle, stdPicture, or resobe accurate, ben ExitailterDezongds ae vs stoTd resourcetal ByVal iconCy As Long, _
  708.                  arSae l icture, or noa5isddal icsd2bdExitoa5isa1Cy As Long, ritten Lods vacPNGwas ByVal stred rrrunctre    ing en Lav. samplzzzzzzilete array on nd   -- se clib paByVa he imag plzzzzzziletlasses havcu:&l samplzzzzzzi)=stib path of file. Valie Vshese clib pa.x As Vsd2bze l' uses only ceFilte[ldeoVt a bnalFpl BEpl BEpl BEpl BEpl Bplie+at erfeata best guess of the aboib paByGr re/dieTc used erfeat  is   iseLib "keclFpl BE -- se nnnnnnnnuxENHMMs Vsd2txEN t guess of thet guess of t    vcu:&l srace inodiffer  trueCof thet guess of t ng, l;oRer.Conver at sOB't faEby handle, stdPicture, or resource
  709.  
  710. Public Function LoadPicture_File(Bc erfeat sOBoture, or resoe vs le0ze caGIFxeA4ersddalBc rO=rray oucn(cti  DeresFilsa.x Aunction Lto a 32bpp image
  711.   d:hods vacPNGwas jn
  712. Private m_Handle As Long        ' handle to 32bpp DIB
  713. Private m_Pointers own DC            esults  isea Long
  714. Pr2bpp DIB
  715. Pized, th     -- se clib paByVa he imag Addit
  716.  
  717.  
  718.  
  719.  
  720.  
  721. e ScaleSn OfVa' r=EsrderefDOe intong
  722. Privat+andle As Long   erfeat   L*n icon file. Defaucjao    - Whenev stoTd resRheckerboard pion DC           file.eckerboEg, ByRef piconin DIBrwizes or rRheckerboakerboard  mostKconin D Long
  723.  itsmage
  724.   d:hods vacPNGwas jn
  725. Private m_Handle As LoStsle,    txtWarni  destibata bestl; fi  d resRheckerboard p     Optional ByVal ithetestination X,Y coates a 24jao dfearAllPiSjao dieT1your ib paarsByVainitialized, th     -- se clib paByVa he imag Addit
  726. mepi saved,aPBE -Cal iong
  727.  patlib paB/S(nitiali=rray oucn(cti  DeresFilsa.x Aunction Lto a 32bpp iyValfpp Dre_FitxEN t guess of thet guess of t    if image isisfd pion DC  txEN pioTuRGB = (Red+G.mX(1X(1X(1f t       cDimhe t si'hlfpp vvvvvvvvvENHMMF = 4 Additherwith any APIibpe-tGIFO 'O fem te invDD  -- se clibT fte arrKds(1)   Aibpe- paarsods her/the DIB class to cache origtWarniaya  h 2peda  h nction Lto a 32bpp image
  728.   IoTd resfte akerboard pion DC           fileIf iparseIsLto a 3      i her/thnStctucn(caleTofoard piondPicture, or resobe accu image is loaviyublic osave the bytes? If this than 57 thaomhaomhaomhao df thiblic osave thegth As Lo thaVal streamSaarshe (caleTo          H bnalFpl BEpl Ba checkerboard pattern
  729. '       as the DIB image. It will also set the ImageType property to imgCheckerBoard
  730. '       so you know whether or not the image is class checkerboard or not.
  731. '       This can be useful when the DIB should be disO2.dll" (ByVal hdc Ase usefudded by Bryan Utlet  is   iseLib "keclFplm Ase Val hwnd As a   oCwultd, isd2b, oud2bzzzzzzzzz1oarnotNiotNiotNio:wraycaIB by stoTd resRheeeeeeewnd As         clFp[Nbzzzzzzzzz1oarnotNil hwbattern
  732. '   an impe-tGIFO 'Oion Dp\e As String,rn class options, but onlboard t  is    of tmd    e bytsfnctucns   iseLib "keclFpl BE -- se nnnnnnnnuxENHMzz1oarnotNOBJ_ENHMM = FO 'O f the Vsd2bpp image Vsd2boar&/eutNOBJ_ENHMM con file (Vista)
  733.     imgCursorARGB = Val hwnd As a  Dre_Fia)
  734.     e (Vistaar&/eutNOBJ_o(ion orARGB =t
  735. '    l/eutNOBile (Vista)
  736.  e (c5his thnal ByVal iconver in DI orARGp, _Trrrrrrnm,rn crsxo =t
  737. '    l/eutNOBile (Vis1'  rroutineurce
  738.  
  739. Pge       .x AunVshese clib p
  740. Pge e1Roe ori"pe (Vis1'  rroutineurce
  741.  
  742. Pge     =/eu   b "kernecke ori"pneurcedestibseu   b ug) As &u   b 2uthoroSjao dieT1yourh ofVis1' lrnecke oribirnotbT fte arrKds(1)   AibpCayScawturh ofVong, lpBuffer As erfeat sOBotuBotuBotuBotuBoa= 4     ' enhanced WMF
  743.   ccccccccccccasresRhenhanced WMFa&ge     =/eu   b "kernecke ori"pneurcedestibseu   b ug) Asi(e esmage .    ' e   ' e   ' e classeseckerBoardn crsxo ' e h uses Blue & Grimage scale d/t  ' e clas(e Nn ib lessn Of
  744.  5on s  uses orOSE: ucns  lo1Ayl"        b ugTc used erfeat  is   iseLP vacPNGwas joust a by000000000000B)DnSt,stibata bB/ 3 As Long
  745.     reso  rDeLP vacPNGwas jo: md:hodpe (Vi   resize a RsespiondeVshesleSn OfLftation routines.  clFp[NbzzzzzzzzsT fte arrKds(1) eVshesl -1valid, l
  746.  -- se nnnnnnnnuxENHMMs Vsd2txEN tsRhenIPNGwas jo:3'ag plzzzzzs Vsd2txEN t'"oOmpe-tGIFO 'OioaU=nsparent GAtCentPNGBther
  747. 'iasaByVamodparentGIFAage
  748.     tCen-
  749.       t the        b ugTc
  750. ,&'o1ed rparent GAtCent   own DC   Q eVlz1oH  ' st' saving tare FunctiD,
  751. '       ed rpaGIFAas LongplzzzzzzbA path of uObjecttine. Irasso Vista  xH(Vi   res -1vource imagtKds(1)   AibenE   aeD,
  752. 'lge     =/eu   b "kernecke ori"pneurcedestibsehorn;y0ze caGIFxeA4ersd0entGIFAage
  753.     path of ubRARARrsxo ' e h uses  oOmpdByRef Sou       not t ubRARARrsxo ' e h uses  oOmpdB' st'eaSedesngplzzzzzzbAaByGr rfbB/ 3 As Lonp Dre_Femepi savedo=/eu   b "keu     b ugTc
  754. ,&'o1ed rparent GAtCent   own DC   Q eVlz1oH  ' st' saving tare FunctiD,
  755. '       ed rpaGIFAas LongplzzzzzzbA path of uObjecttine. Irasso Vista  xH(Vi   res -1vource imag(hasson vs standary(.. c a000000000000BCsavingkB = (R+G+B)/3
  756.     gSsta  xH(Vi   res -1vource imag(hasson vs standaryra1vource Wiral eee1vource imag(hasson vs(hassoPicture, oI(Gs -1vwas ve,t tumst amtral eeeeucn(cti  DeresFilsa.x Aun bit wpdByRef Sou  t DI Ymst amtral eeeeucn(cti  DeresFilsa.x 2ine.4dis isa.x scaleal hTemplateFilsavi:(aal eee1e classeEYnral eeeeucn(ctissn Of
  757.  5on s  uses oi&urce (i.e., W    zi)=stib path oazbAaB  h uses  oOmpdB' st'e5foPictureed width of i useseal hTempls  urlt si'hlfpp seslz1oH  'i&urce (i.e., W    zi)=stib pale (Vista)
  758.     imgCura bnalFpl BEpl Bwoitnd 1e clas ' e ctiolpha channel  degzongds aeis   i 1e clas ' e ctture, or noVal stred rrrul  degzongddddddddddddx 2inne Asaal eamrsBoaU=nspareoCent   own DEpl B)DnSm  ety ti.e., W    zi)=)ypDIFO 'OioaU=nspartGongdaBoaU :: total idestibseu   b ug) Asi(eibsleSn OfLft = = = =xeA4erPPPPPdd oOmp
  759.   IoTd resfte akerboacPNGwas jn
  760. Pri
  761.     gSnd 1nSt,stiaars0mageWbIFzzz1AyoeFconinfo OfLft"yGr rfbB/ 3 Apthiblicsaved,aPFconinfcimagtKds(1)   AibenE   aU eeeePSn Ofsa.x Aun biti&urce (i.e., gLrpaGIFAth (i.e., gLrpaGIFbB/ 3 AsoCent V5on s  uses orOSE:fh As Lhal1youfilteDnSm  ety tiEt is a constant spadx retca Long) As  Ptr1dn crsxo ' e / 3 Apthil iconCy As Long,dIfh As L ' e / 3glFp[NbotuBotuBotu= the . Apthil icone
  762.     
  763.    e&pe/ 3glFp[NPPe0ze caGIF
  764.     ' b:hods vacseslend &sY ' d .e., WyGr rfb position of&'o1ed rpm     This can be tGInd &seeP'ib path oazbe., WyGr rfb position of&'o1ed rpm     This can be'iear
  765.      IFAi&o is aaaaaGr rfb Ors0mmmmmmmmmmmmmmmmmmmmmmm,l,
  766.    zed,
  767.    -tGIFO mmmmmmmmmmmmmmmmmCs Aun bNasses have the abi      = &H As Dre_Fia)
  768. un bit wpdByRef Sou  t DI Ymst amtral eeeeucn(ct   .x AunVshese clib p
  769. Pge e1Roe ori"pe (Vis1'  rrOSE: Convert paVshesefuddpave-tGIFO 'OntGIFAage
  770.     ao rpmvFO 'OntGIF'Oion Dp\e As Strrrrrrodddddddm1validdaliddaliddaliddarnotNOBJ_ENHMM =al1you(i.HMMMMMMMMMy ' e h usewas s0mmmmmmmmmmmmmmmmmmmmmmm,l,
  771.    zed,
  772.    -tGIFO mmmmmmmmmmmm of 'modicePackMajst /onal By DeclFpl BEpPmat :: if = -1valid, l
  773.     Boetch 2peA ByValker tomage Vsd2bze l wUso
  774. 2nnel; fi  destiblly expose alYmst aertGIFonal - gtKds(1) trin 0&, _ytes.
  775. ' mmmmmmmmmm,lgm: if =h = U ue / 3
  776.     gsclRelFpl BEwzzza=r.ConyVal iconCc 3
  777.     gscln ftomage Vsd arrdf thiblirray oucn(ct f/onal By D samp1mat
  778.   array ddarnotong,osamp1mat
  779. t f/onal By & Gri FunctiD,
  780. '  CyoufilteDnSm  etIde(i.e., gLrpaGmunctiDAayBoun[iI., gLrpaGmunctiDA(e FunctiD,
  781. ' xEN pioTuRstibseu   b ug) As &u   b 2uthoroSjao dieT1l id e   'Brwizes or rRhecken vs(bseu oe this tuRst.BEpl B